package net.optix.ip.vo
{
	import mx.collections.ArrayCollection;
	
	public class QuarterInventionVO
	{
		public static var quarters:Array	=	
				['Q1','Q2','Q3','Q4'];
				
		public var quarter:String;
		
		public var avCostPerPa:Number	=	0;
		public var avCostPerAb:Number	=	0;
		public var avOARPerPa:Number	=	0;
		public var avOARPerAb:Number	=	0;
		
		public var sumFillingCost:Number	=	0;
		public var sumResponseCost:Number	=	0;

		public var numInventionAb:int;
		public var numInventionIss:int;
		
			
		public var avRCEsPerPa;
		public var avRCEsPerAb;
		public var avAppPerPa;
		
		public var avAppealsPerAbandonment;
		
		
			
		public static function purseInvention(inventions:XML):ArrayCollection
		{
			var quarters:ArrayCollection	=	new ArrayCollection();
			for(var i:int=0; i<4; i++)
			{
				var vo:QuarterInventionVO	=	new QuarterInventionVO();
				vo.quarter					=	QuarterInventionVO.quarters[i];
				quarters.addItem(vo);
			}
			
			try
			{
				for(var i:int=0; i<inventions.Data.length(); i++)
				{
					var month:int	=	inventions.Data[i].Month;
					var status:int	=	inventions.Data[i].Status;
					var quarter:QuarterInventionVO	=	quarters[int((month-1)/3)];
					trace("Quarter is "+quarter.quarter);
					if(status == 9)
					{
						quarter.numInventionIss	+=	1;
					}
					else if(status == 10)
					{
						quarter.numInventionAb	+=	1;
					}
					
					quarter.sumFillingCost	+=	inventions.Data[i].SumFillingCost;
					quarter.sumResponseCost	+=	inventions.Data[i].SumResponseCost;
					
				}
			}
			catch(error:Error)
			{
					
			}
			for(var i:int=0; i<4; i++)
			{
				QuarterInventionVO.calculate(quarters[i]);
			}
			return quarters;
		}
		
		public static function calculate(quarter:QuarterInventionVO):void
		{
			trace(quarter.quarter+"  sum filling cost is "+quarter.sumFillingCost);
			trace(quarter.quarter+"  sum response cost is "+quarter.sumResponseCost);
			trace(quarter.quarter+"  num parent is "+quarter.numInventionIss);
			trace(quarter.quarter+"  num ab is "+quarter.numInventionAb);
			try
			{
				if(quarter.numInventionIss > 0)
				{
					quarter.avCostPerPa	=	quarter.sumFillingCost/quarter.numInventionIss;
					quarter.avOARPerPa	=	quarter.sumResponseCost/quarter.numInventionIss;
				}
				if(quarter.numInventionAb > 0)
				{
					quarter.avCostPerAb	=	quarter.sumFillingCost/quarter.numInventionAb;
					quarter.avOARPerAb	=	quarter.sumResponseCost/quarter.numInventionAb;
				}
			}
			catch(error:Error){}
		}
	}
	
}